package org.ricks.log;

/**
 * @author chenwei
 * @Description:日志输出实现
 * @date 2023/1/916:33
 */
interface Appender {


    /**
     * 输出日志消息.
     *
     * @param event 一次日志记录
     * @param text  输出内容
     */
    void output(LogEvent event, char[] text);

    /**
     * 控制台Appender
     */
    class ConsoleAppender implements Appender {
        @Override
        public void output(LogEvent event, char[] text) {
            switch (event.getLevel()) {
                case DEBUG:
                case INFO:
                    System.out.print(text);
                    break;
                default:
                    System.err.print(text);
                    break;
            }
        }
    }

    /**
     * 文件Appender
     */
    class FileAppender implements Appender {

        @Override
        public void output(LogEvent event, char[] text) {
            LogManager.init().output(event, text);
        }
    }
}